//
//  LPChooseActAndResouceTypeView.m
//  ShangHaiHuDongApp
//
//  Created by 刘应平 on 2017/8/5.
//  Copyright © 2017年 刘应平. All rights reserved.
//

#import "LPChooseActAndResouceTypeView.h"

@implementation LPChooseActAndResouceTypeView

- (instancetype)initWithFrame:(CGRect)frame titles:(NSArray *)titles
{
    self = [super initWithFrame:frame];
    if (self) {
        CGFloat width = [UIScreen zj_screenWith] / titles.count;
        for (int i = 0; i < titles.count; i ++) {
            UIButton *button = [UIButton new];
            button.frame = CGRectMake(width * i, 0, width - 1, self.height);
            button.tag = i;
            [button setTitle:titles[i] forState:UIControlStateNormal];
            [button setTitleColor:[UIColor textGrayColor] forState:UIControlStateNormal];
            [button setImage:[UIImage imageNamed:@"sign_select_more"] forState:UIControlStateNormal];
            button.titleLabel.font = LYPFONT(15);
            button.titleLabel.textAlignment = NSTextAlignmentCenter;
            [button addTarget:self action:@selector(clickButton:) forControlEvents:UIControlEventTouchUpInside];
            
            UIView *line = [UIView new];
            line.frame = CGRectMake(width - 1 + width * i,self.height * 0.15, 1, self.height * 0.7);
            line.backgroundColor = [UIColor themeGrayColor];
            
            [self addSubview:button];
            if (i != titles.count - 1) {
                [self addSubview:line];
            }
            if ([titles[i] isEqualToString:@"分类  "]) {
                self.postionButton = button;
            }
            /**  调整图片和文字的位置  */
            [UIButton moveButtonLeftTitleAndRightImage:button];
            
        }
        
        UIView *under = [UIView new];
        under.backgroundColor = [UIColor themeGrayColor];
        [self addSubview:under];
        under.sd_layout.leftEqualToView(self).bottomEqualToView(self).widthIs([UIScreen zj_screenWith]).heightIs(1.5);
    }
    return self;
}


- (void)clickButton:(UIButton *)sender{
    if (self.delegate) {
        [self.delegate LPChooseActAndResouceTypeView_delegate_clickView:sender clickIndex:sender.tag];
    }

}

@end
